package com.davies.learn.jbv.configuration;


import com.davies.learn.jbv.domain.dto.UserSaveDTO;
import com.davies.learn.jbv.domain.dto.UserTypeGroup;
import com.google.common.collect.Lists;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.List;

/**
 * @author davies
 * @date 2023/7/18 16:05
 */
public class UserTypeGroupSequenceProvider implements DefaultGroupSequenceProvider<UserSaveDTO> {


    @Override
    public List<Class<?>> getValidationGroups(UserSaveDTO object) {
        List<Class<?>> groups = Lists.newArrayList(UserSaveDTO.class);
        if (object == null||object.getUserType()==null) {
            return groups;
        }
        switch (object.getUserType()) {
            case VIP -> groups.add(UserTypeGroup.Vip.class);
            case S_VIP -> groups.add(UserTypeGroup.SVip.class);
            default -> groups.add(UserTypeGroup.Normal.class);
        }
        return groups;
    }
}
